//
//  DDLoginViewController.m
//  LYJR_XDD
//
//  Created by 肖棟棟 on 16/8/6.
//  Copyright © 2016年 肖棟棟. All rights reserved.
//

#import "DDLoginViewController.h"
#import "DDOpenAccountViewController.h"
#import "DDForgetPasswordViewController.h"

@interface DDLoginViewController ()

//图标
@property (nonatomic, strong) UIImageView *logoImageView;
//图标文本
@property (nonatomic, strong) UILabel *logoLb;
//小文本
@property (nonatomic, strong) UILabel *smallLb;
//手机号view
@property (nonatomic, strong) UIView *phoneView;
//密码view
@property (nonatomic, strong) UIView *passwordView;
//忘记密码按钮
@property (nonatomic, strong) UIButton *forgetPasswordBtn;

//登录按钮
@property (nonatomic, strong) UIButton *loginBtn;
//开户按钮
@property (nonatomic, strong) UIButton *openAccountBtn;
//随便逛逛按钮
@property (nonatomic, strong) UIButton *lookWhereBtn;


@property (nonatomic, strong) UITextField *loginPhoneTextField;
@property (nonatomic, strong) UITextField *passwordTextField;



@end

@implementation DDLoginViewController


-(void)viewWillAppear:(BOOL)animated{
  
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor = [UIColor whiteColor];
    
    //    [self.navigationController setNavigationBarHidden:YES animated:YES];
    //创建UI
    [self createLoginUI];
    [self setNavButton];
    
    
    //注册键盘监听
    NSNotificationCenter *center=[NSNotificationCenter defaultCenter];
    //添加注册监听  self 监听键盘自动发出的UIKeyboardWillChangeFrameNotification通知，调用self的keyboardFrameChange:进行处理
    [center addObserver:self selector:@selector(keyboardFrameChange:) name:UIKeyboardWillChangeFrameNotification object:nil];
}

#pragma mark - 私有方法

//键盘监听处理方法
- (void) keyboardFrameChange:(NSNotification *)notice
{
    //NSLog(@"%@",notice.userInfo);
    //1.获取动画时间
    CGFloat time=[notice.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
    CGFloat endY=[notice.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].origin.y;
    //获取偏移值
    CGFloat offset=endY-self.view.bounds.size.height;
    
    [UIView animateWithDuration:time animations:^{
        self.view.transform=CGAffineTransformMakeTranslation(0, offset);
    }];
}

//移除监听
- (void) dealloc
{
    NSNotificationCenter *center=[NSNotificationCenter defaultCenter];
    [center removeObserver:self];
}

- (void)createLoginUI{
    //图标
    UIImageView *bgImageView = [[UIImageView alloc]init];
    bgImageView.image = [UIImage imageNamed:@"wallhaven-313258 "];
    //背景view
    [self.view addSubview:bgImageView];
    
    
    //图标
    UIImageView *logoImageView = [[UIImageView alloc]init];
    logoImageView.image = [UIImage imageNamed:@"logo"];
    
    [bgImageView addSubview:logoImageView];
    
    UIImageView *phoneImageView = [[UIImageView alloc]init];
    phoneImageView.image = [UIImage imageNamed:@"Group 1"];
    
    UIImageView *passwordImageView = [[UIImageView alloc]init];
    passwordImageView.image = [UIImage imageNamed:@"Group 4"];
    UIImageView *imageView = [[UIImageView alloc]init];
    imageView.image = [UIImage imageNamed:@"Group 14"];
    [bgImageView addSubview:imageView];
    
   
    //图标文本
    [self.view addSubview:self.logoLb];
    //小文本
    [self.view addSubview:self.smallLb];
    //手机号view
    [self.view addSubview:self.phoneView];
    [self.phoneView addSubview:phoneImageView];
    [self.phoneView addSubview:self.loginPhoneTextField];
    
    //密码view
    [self.view addSubview:self.passwordView];
    [self.passwordView addSubview:passwordImageView];
    [self.passwordView addSubview:self.passwordTextField];
    
    //忘记密码按钮
    [self.view addSubview:self.forgetPasswordBtn];
    //登录按钮
    [self.view addSubview:self.loginBtn];
    //开户按钮
    [self.view addSubview:self.openAccountBtn];
    //随便逛逛按钮
    [self.view addSubview:self.lookWhereBtn];
    
    //添加约束
    [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.mas_equalTo(self.view);
        
    }];
    
    [logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).offset(79);
        make.centerX.mas_equalTo(self.view);
        make.height.mas_equalTo(219/2);
        make.width.mas_equalTo(122/2);
        
    }];
    
    [_logoLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(logoImageView.mas_bottom).offset(15);
        make.centerX.mas_equalTo(self.view);
    }];
    
    [_smallLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_logoLb.mas_bottom).offset(10);
        make.centerX.mas_equalTo(self.view);
    }];
    
    [_phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).offset(280);
        make.left.mas_equalTo(self.view).offset(15);
        make.right.mas_equalTo(self.view).offset(-15);
        make.height.mas_equalTo(50);
    }];
    [phoneImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_phoneView).offset(12);
        make.bottom.mas_equalTo(_phoneView).offset(-12);
        make.left.mas_equalTo(_phoneView).offset(10);
        make.width.mas_equalTo(phoneImageView.mas_height);
    }];
    
    [_loginPhoneTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(phoneImageView);
        make.left.mas_equalTo(phoneImageView.mas_right).offset(10);
        make.right.mas_equalTo(_phoneView);
    }];
    
    
    [_passwordView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_phoneView.mas_bottom).offset(15);
        make.left.right.height.mas_equalTo(_phoneView);
    }];
    [passwordImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_passwordView).offset(12);
        make.bottom.mas_equalTo(_passwordView).offset(-12);
        make.left.mas_equalTo(_passwordView).offset(10);
        make.width.mas_equalTo(passwordImageView.mas_height);
    }];
    [_passwordTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(passwordImageView);
        make.left.mas_equalTo(passwordImageView.mas_right).offset(10);
        make.right.mas_equalTo(_passwordView);
    }];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_passwordView.mas_bottom).offset(15);
        make.right.mas_equalTo(_passwordView);
        make.width.height.mas_offset(11);
    }];
    
    [_forgetPasswordBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(imageView);
        make.right.mas_equalTo(imageView.mas_left).offset(-4);
    }];
    
    [_loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(imageView.mas_bottom).offset(15);
        make.left.right.height.mas_equalTo(_phoneView);
    }];
    
    [_openAccountBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_loginBtn.mas_bottom).offset(15);
        make.left.right.height.mas_equalTo(_phoneView);
    }];
    
    [_lookWhereBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.view).offset(-15);
        make.centerX.mas_equalTo(self.view);
    }];
    
}

#pragma mark - 私有方法
-(void)setNavButton{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Group 51"] style:UIBarButtonItemStylePlain target:self action:@selector(backBtnDidClick)];
}

-(void)backBtnDidClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)loginBtnDidClick{
    NSLog(@"登陆按钮点击");
   
    
}

-(void)openAccountBtnDidClick{
    NSLog(@"开户按钮点击");
    DDOpenAccountViewController * openVc = [[DDOpenAccountViewController alloc] init];
    [self.navigationController pushViewController:openVc animated:YES];
}

-(void)forgetPasswordBtnDidClick{
    DDForgetPasswordViewController * fgVc = [[DDForgetPasswordViewController alloc] init];
    
    [self.navigationController pushViewController:fgVc animated:YES];
    
}


-(void)lookWhereBtnDidClick{
    
}






#pragma mark - 懒加载

-(UILabel *)logoLb{
    if (_logoLb == nil) {
        _logoLb = [[UILabel alloc] init];
        _logoLb.text = @"猎鹰金融";
        _logoLb.textColor = [UIColor colorWithHexColor:@"#FCC158"];
        _logoLb.font =[UIFont systemFontOfSize:24];
    }
    return _logoLb;
}

-(UILabel *)smallLb{
    if (_smallLb == nil) {
        _smallLb = [[UILabel alloc] init];
        _smallLb.textColor = [UIColor colorWithHexColor:@"#DBAA7B"];
        _smallLb.text = @"yingmeiyuan.com";
        
    }
    return _smallLb;
}

-(UIView *)phoneView{
    if (_phoneView == nil) {
        _phoneView = [[UIView alloc] init];
        _phoneView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"690 100 131 Copy"]];
        
    }
    return _phoneView;
}

-(UIView *)passwordView{
    if (_passwordView == nil) {
        _passwordView = [[UIView alloc] init];
        _passwordView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"690 100 131 Copy"]];
    }
    return _passwordView;
}

-(UIButton *)forgetPasswordBtn{
    if (_forgetPasswordBtn == nil) {
        _forgetPasswordBtn = [[UIButton alloc] init];
        [_forgetPasswordBtn setTitle:@"忘记密码" forState:UIControlStateNormal];
        _forgetPasswordBtn.titleLabel.font=[UIFont systemFontOfSize:12];
        [_forgetPasswordBtn setTitleColor:[UIColor colorWithHexColor:@"#A7ABB4"] forState:UIControlStateNormal];
        [_forgetPasswordBtn addTarget:self action:@selector(forgetPasswordBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _forgetPasswordBtn;
}
-(UIButton *)loginBtn{
    if (_loginBtn == nil) {
        _loginBtn = [[UIButton alloc] init];
        [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
        _loginBtn.titleLabel.font=[UIFont systemFontOfSize:18];
        [_loginBtn setTitleColor:[UIColor colorWithHexColor:@"#191A27"] forState:UIControlStateNormal];
        [_loginBtn setBackgroundImage:[UIImage imageNamed:@"Rectangle 184"] forState:UIControlStateNormal];
        
        [_loginBtn addTarget:self action:@selector(loginBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _loginBtn;
}

-(UIButton *)openAccountBtn{
    if (_openAccountBtn == nil) {
        _openAccountBtn = [[UIButton alloc] init];
        [_openAccountBtn setTitle:@"开户" forState:UIControlStateNormal];
        _openAccountBtn.titleLabel.font=[UIFont systemFontOfSize:18];
        [_openAccountBtn setTitleColor:[UIColor colorWithHexColor:@"#FFCB6F"] forState:UIControlStateNormal];
        [_openAccountBtn setBackgroundImage:[UIImage imageNamed:@"Group 6"] forState:UIControlStateNormal];
        [_openAccountBtn addTarget:self action:@selector(openAccountBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _openAccountBtn;
}

-(UIButton *)lookWhereBtn{
    
    if (_lookWhereBtn == nil) {
        _lookWhereBtn = [[UIButton alloc] init];
        [_lookWhereBtn setTitleColor:[UIColor colorWithHexColor:@"#66666B"] forState:UIControlStateNormal];
        [_lookWhereBtn setTitle:@"随便逛逛" forState:UIControlStateNormal];
        _lookWhereBtn.titleLabel.font=[UIFont systemFontOfSize:12];
        [_lookWhereBtn addTarget:self action:@selector(lookWhereBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _lookWhereBtn;
}

- (UITextField *)loginPhoneTextField{
    if (_loginPhoneTextField == nil) {
        _loginPhoneTextField = [[UITextField alloc]init];
        _loginPhoneTextField.placeholder = @"手机号/邮箱";
        //        _loginPhoneTextField.keyboardType = UIKeyboardTypeNumberPad;
        _loginPhoneTextField.font = [UIFont systemFontOfSize:15];
        _loginPhoneTextField.textColor= [UIColor colorWithHexColor:@"868691"];
        
    }return _loginPhoneTextField;
}

- (UITextField *)passwordTextField{
    if (_passwordTextField == nil) {
        _passwordTextField = [[UITextField alloc]init];
        _passwordTextField.placeholder = @"密码";
        _passwordTextField.font = [UIFont systemFontOfSize:15];
        _passwordTextField.secureTextEntry = YES;
        _passwordTextField.textColor= [UIColor colorWithHexColor:@"868691"];
        
    }return _passwordTextField;
}

@end
